package com.zack.dispatch;

/**
 * @author zack
 * @create 2019-08-04-15:00
 */
public class CompetitionSchedule {
    public void ScheduleTable(int table[][], int n) {
        if (n == 1) {
            table[0][0] = 1;
        } else {
            int m = n / 2;
            //填充左上区的矩阵
            //递归的把n/2 直到n==1
            ScheduleTable(table, m);
            // 填充右上区的矩阵
            for (int i = 0; i < m; i++) {
                for (int j = m; j <= n - 1; j++) {
                    //二维数组位置上差4
                    table[i][j] = m + table[i][j - m];
                }
            }
            // 填充左下区的矩阵
            for (int i = m; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    table[i][j] = table[i - m][j] + m;
                }
            }
            // 填充右下区的矩阵
            for (int i = m; i < n; i++) {
                for (int j = m; j < n; j++) {
                    table[i][j] = table[i - m][j - m];
                }
            }

        }
    }

    public static void main(String[] args) {
        int[][] table = new int[8][8];
        int n = 8;
        CompetitionSchedule competitionSchedule = new CompetitionSchedule();
        competitionSchedule.ScheduleTable(table, n);
        int c = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(table[i][j] + " ");
                c++;
                if (c % n == 0) {
                    System.out.println();
                }
            }

        }
    }
}
